#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;

int n, m, a, b;
int v[N][N];
ll sum[N][N];
deque<int> dq[N];
struct Node {
  int x, y;
  ll cost;
  bool operator<(const Node& o) const {
    if (cost != o.cost) return cost < o.cost;
    if (x != o.x) return x < o.x;
    return y < o.y;
  }
} rects[N * N];
int num;
bool vis[N][N];
void update(int x, int y) {
  rep(i, x, x + a - 1) rep(j, y, y + b - 1) vis[i][j] = 1;
}
bool check(int x, int y) { return vis[x][y]; }
void solve() {
  cin >> n >> m >> a >> b;
  rep(i, 1, n) rep(j, 1, m) cin >> v[i][j];
  rep(i, 1, n) rep(j, 1, m) sum[i][j] =
      sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + v[i][j];
  rep(j, 1, m) {
    rep(i, 1, n) {
      while (dq[i].size() && v[i][dq[i].back()] >= v[i][j]) dq[i].pop_back();
      dq[i].push_back(j);
      while (dq[i].size() && dq[i].front() + b <= j) dq[i].pop_front();
    }
    if (j < b) continue;
    deque<int> now;
    rep(i, 1, n) {
      while (now.size() &&
             v[now.back()][dq[now.back()].front()] >= v[i][dq[i].front()])
        now.pop_back();
      now.push_back(i);
      while (now.size() && now.front() + a <= i) now.pop_front();
      if (i < a) continue;
      int x = v[now.front()][dq[now.front()].front()];
      rects[++num] = {i - a + 1, j - b + 1,
                      sum[i][j] - sum[i - a][j] - sum[i][j - b] +
                          sum[i - a][j - b] - 1ll * x * a * b};
    }
  }
  sort(rects + 1, rects + num + 1);
  vector<int> ans;
  rep(i, 1, num) {
    int x = rects[i].x, y = rects[i].y;
    int cnt = check(x + a - 1, y + b - 1) + check(x, y + b - 1) +
              check(x + a - 1, y) + check(x, y);
    if (cnt) continue;
    ans.push_back(i);
    update(x, y);
  }
  cout << ans.size() << endl;
  for (int i : ans)
    cout << rects[i].x << ' ' << rects[i].y << ' ' << rects[i].cost << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}